import styles from "./index.less";
import { connect } from "dva";
import { NavBar, Icon } from "antd-mobile";
import router from "umi/router";
import withRouter from "umi/withRouter";
import config from "utils/config";
const { prefix, openPages, routeTotitle } = config;

const Layout = props => {
  if (openPages && openPages.includes(props.pathname)) {
    return <div> {props.children}</div>;
  }
  return (
    <div>
      <NavBar
        mode="dark"
        className={styles.barColor}
        style={{
          backgroundColor: "#FFF",
          fontFamily: "PingFangSC-Medium",
          fontSize: ".36rem",
          color: "#000000",
          textAign: "center",
          lineHeight: ".36rem"
        }}
        icon={
          props.pathname === "/mainpage" || props.pathname === "/" ? null : (
            <Icon
              type="left"
              style={{
                fontSize: ".44rem"
              }}
            />
          )
        }
        onLeftClick={() => {
          //这里需要做指定式跳转，手机页面会涉及到用户刷新的问题
          if (props.pathname === "/mainpage" || props.pathname === "/") {
            return;
          } else if (props.pathname === "/promotion") {
            router.push("mainpage");
            return;
          }
          try {
            router.go(-1);
          } catch (error) {
            router.push("mainpage");
          }
        }}
      >
        {routeTotitle[props.pathname]}
      </NavBar>
      {props.children}
    </div>
  );
};
function mapStateToProps(state) {
  return {
    text: state.global.text,
    pathname: state.routing.location.pathname
  };
}
export default withRouter(connect(mapStateToProps)(Layout));
